| Conditions | 1 |
| Paths | 2 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import path from 'path' |
||
| 139 | export function getFilesMerged(files) { |
||
| 140 | var merged = {} |
||
| 141 | var arMerged = [] |
||
| 142 | |||
| 143 | Array.prototype.forEach.call(files, (file) => { |
||
| 144 | var cleanFilePath = file.cleanFilePath |
||
| 145 | |||
| 146 | var fileStatusIsPublish = cmsData.fileAttr.get(file.cleanPath) |
||
| 147 | if(fileStatusIsPublish.s != null && file.abe_meta.status === 'publish') { |
||
| 148 | file.abe_meta.status = 'draft' |
||
| 149 | } |
||
| 150 | |||
| 151 | file.html = path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)) |
||
| 152 | if (file.abe_meta.status === 'publish') { |
||
| 153 | file.htmlPath = path.join(config.root, config.publish.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 154 | }else { |
||
| 155 | file.htmlPath = path.join(config.root, config.draft.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 156 | } |
||
| 157 | |||
| 158 | if(merged[cleanFilePath] == null) { |
||
| 159 | merged[cleanFilePath] = { |
||
| 160 | name: cmsData.fileAttr.delete(file.name), |
||
| 161 | path: cmsData.fileAttr.delete(file.path), |
||
| 162 | html: cmsData.fileAttr.delete(path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))), |
||
| 163 | htmlPath: path.join(config.root, config.publish.url, path.join('/', cmsData.fileAttr.delete(file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)))), |
||
| 164 | cleanPathName: file.cleanPathName, |
||
| 165 | cleanPath: file.cleanPath, |
||
| 166 | cleanName: file.cleanName, |
||
| 167 | cleanNameNoExt: file.cleanNameNoExt, |
||
| 168 | cleanFilePath: file.cleanFilePath, |
||
| 169 | filePath: cmsData.fileAttr.delete(file.filePath), |
||
| 170 | revisions: [] |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | merged[cleanFilePath].revisions.push(JSON.parse(JSON.stringify(file))) |
||
| 175 | }) |
||
| 176 | |||
| 177 | // return merged |
||
| 178 | Array.prototype.forEach.call(Object.keys(merged), (key) => { |
||
| 179 | var revisions = merged[key].revisions |
||
| 180 | revisions.sort(coreUtils.sort.predicatBy('date', -1)) |
||
| 181 | if(revisions[0] != null) { |
||
| 182 | merged[key].date = revisions[0].date |
||
| 183 | } |
||
| 184 | |||
| 185 | Array.prototype.forEach.call(revisions, (revision) => { |
||
| 186 | |||
| 187 | var status = revision.abe_meta.status |
||
| 188 | |||
| 189 | if (status === 'publish') { |
||
| 190 | merged[key][status] = revision |
||
| 191 | }else { |
||
| 192 | merged[key][status] = {} |
||
| 193 | } |
||
| 194 | merged[key][status].path = revision.path |
||
| 195 | merged[key][status].html = revision.html |
||
| 196 | merged[key][status].htmlPath = revision.htmlPath |
||
| 197 | merged[key][status].date = new Date(revision.date) |
||
| 198 | merged[key][status].link = revision.abe_meta.link |
||
| 199 | }) |
||
| 200 | |||
| 201 | merged[key].revisions = revisions |
||
| 202 | |||
| 203 | merged[key].date = revisions[0].date |
||
| 204 | merged[key].cleanDate = revisions[0].cleanDate |
||
| 205 | merged[key].duration = revisions[0].duration |
||
| 206 | merged[key].abe_meta = revisions[0].abe_meta |
||
| 207 | |||
| 208 | arMerged.push(merged[key]) |
||
| 209 | }) |
||
| 210 | |||
| 211 | return arMerged |
||
| 212 | } |